<?php
/**
 * Created by PhpStorm.
 * User: jianglong
 * Date: 2017/11/16
 * Time: 上午9:19
 */

namespace plugins\StatInfo;


use app\common\controller\Plugin;
use think\Db;
class StatInfo extends Plugin
{
    public $info = [
        'name' => 'StatInfo',
        'title' => '统计消息',
        'identifier' => 'statinfo.lance.plugin',
        'author' => 'jianglong1992',
        'version' => '1.0.0',
        'description' => "客户经理和领导后台首页信息展示"
    ];
    public $hooks = [
        'leader_index' => '领导首页',
        'manager_index' =>  '客户经理首页'
        //'manager_index' => '客户经理首页',

    ];

    public function leaderIndex(){
        $i_roleId = Db::name('admin_user')->where('id',UID)->value('role_id');
        $a_info = Db::name('manager')->where('id',$i_roleId)->find();
        $this->fetch('leaderIndex',[
            'info' => $a_info,
        ]);
    }
    public function managerIndex(){
        $i_roleId = Db::name('admin_user')->where('id',UID)->value('role_id');
        $a_info = Db::name('manager')->where('id',$i_roleId)->find();
        //待处理领导消息
        $i_msgNum = Db::name('event_log')->where('manager_id',MANAGER_ID)->where([
            'send_id' => ['not in',[0,1]],
            'status' => 0
        ])->count();
        $i_adminNum = Db::name('event_log')->where('manager_id',MANAGER_ID)->where([
            'send_id' => ['eq',1],
            'status' => 0
        ])->count();
        //系统消息
        $i_sysNum = Db::name('event_log')->where('manager_id',MANAGER_ID)->where([
            'send_id' => 0,
            'status' => 0
        ])->count();
        //待接收客户
        $i_turnNum = Db::name('customer_turn_log')->where([
            'manager_id' => MANAGER_ID,
            'status' => 0,
            'next_log' => 0
        ])->count();
        $this->fetch('managerIndex',[
            'info' => $a_info,
            'message_num' => $i_msgNum,
            'sys_num' => $i_sysNum,
            'admin_num' => $i_adminNum,
            'turn_num' => $i_turnNum
        ]);
    }
    public function install()
    {
        // TODO: Implement install() method.
        return true;
    }

    public function uninstall()
    {
        // TODO: Implement uninstall() method.
        return true;
    }

}